home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 7
/
Apprentice-Release7.iso
/
Environments
/
Small Eiffel 0.4.8
/
lib_rand
/
std_rand.e
< prev
Wrap
Text File
|
1997-04-13
|
1KB
|
87 lines
-- Part of SmallEiffel -- Read DISCLAIMER file -- Copyright (C)
-- Dominique COLNET and Suzanne COLLIN -- colnet@loria.fr
--
class STD_RAND
-- Press' standard generator, which uses the minimal standard
-- and then uses shuffling to break up short order corelations.
inherit
MIN_STAND
redefine with_seed, next
select with_seed, next
end;
MIN_STAND
rename
next as min_next
export
{NONE} min_next
redefine
last_integer, last_real
end;
creation make, with_seed
feature {NONE}
iv: ARRAY[INTEGER];
ntab: INTEGER is 32;
iy: INTEGER;
feature {NONE}
with_seed(seed_value:INTEGER) is
require
valid_seed: seed_value > 0 and seed_value < im
local
i: INTEGER;
do
seed := seed_value;
min_next;
!!iv.make(1,ntab);
from
i := 1;
until
i > 7
loop
min_next;
i := i + 1;
end;
from
i := ntab;
until
i = 0
loop
iv.put(seed,i);
min_next;
i := i - 1;
end
iy := iv.item(1);
next;
end
feature
next is
local
tmp:INTEGER
do
tmp := iy \\ ntab + 1;
min_next;
iy := iv.item(tmp);
iv.put(seed,tmp);
end
last_integer(n:INTEGER):INTEGER is
do
Result := iy \\ n + 1;
end
last_real:REAL is
do
Result := (iy / im).to_real;
end
end